package com.wyp168.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName CountMatchesSolution
 * @Title TODO
 * @Description TODO
 * @Author wyp168`
 * @Date 2022/10/29 01:14
 */
public class CountMatchesSolution {
    public static void main(String[] args) {
        CountMatchesSolution solution = new CountMatchesSolution();
        List<List<String>> items = new ArrayList<>();
        List<String> item1 = new ArrayList<>();
        item1.add("phone");
        item1.add("blud");
        item1.add("pixel");

        List<String> item2 = new ArrayList<>();
        item2.add("computer");
        item2.add("silver");
        item2.add("lenovo");

        List<String> item3 = new ArrayList<>();
        item3.add("phone");
        item3.add("silver");
        item3.add("lenovo");
        items.add(item1);
        items.add(item2);
        items.add(item3);

        String ruleKey = "type";
        String ruleValue = "phone";

        System.out.println(solution.countMatches(items, ruleKey, ruleValue));
    }

    public int countMatches(List<List<String>> items, String ruleKey, String ruleValue) {
        return (int) items.stream().map(item -> {
            if (ruleKey.equals("type")) {
                return item.get(0);
            }
            if (ruleKey.equals("color")) {
                return item.get(1);
            }
            if (ruleKey.equals("name")) {
                return item.get(2);
            }
            return "";
        }).filter(s -> s.equals(ruleValue)).count();
    }
}
